//
//  FLHttpCommunicate.h
//  faceLooker
//
//  Created by yww on 2018/12/28.
//  Copyright © 2018年 yww. All rights reserved.
//

#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import "FLHttpCommentDefine.h"

 
typedef void (^OptionDict)(NSDictionary *dict);
typedef void (^OptionError)(NSError *error);
typedef void (^OptionData)(NSData *data);
typedef NS_ENUM (NSInteger , HTTPRequestMethod)
{
    POST = 0,
    GET,
    PUT,
    DELETE
};
 

@interface FLHttpCommunicate : NSObject
+ (id)sharedInstance;

#pragma mark - 枚举接口管理请求类
/**
 *  HTTP请求
 *
 *  @param taskID   服务器提供的接口，用一个枚举来管理
 *  @param param    传的参数
 *  @param method   GET,POST,DELETE,PUT方法
 *  @param success  请求完成
 *  @param failure  请求失败
 *  @param LMowView 界面上显示的网络加载进度状态(nil为不显示)
 */
+ (void)createRequest:(HTTP_COMMAND_LIST)taskID
            WithParam:(NSDictionary *)param
           withMethod:(HTTPRequestMethod)method
              success:(void(^)(id result))success
              failure:(void(^)(NSError *erro))failure
              showHUD:(UIView *)LMowView;


#pragma mark - 文件上传与下载
/**
 *  上传文件功能，如图片等
 *
 *  @param taskID             服务器提供的接口，用一个枚举来管理
 *  @param param              传的参数
 *  @param Exparam            文件流，将要上传的文件转成NSData中，然后一起传给服务器
 *  @param method             GET,POST,DELETE,PUT方法
 *  @param success            请求完成
 *  @param uploadFileProgress 请求图片的进度条，百分比
 *  @param failure            请求失败
 */
+ (void)createRequest:(HTTP_COMMAND_LIST)taskID
            WithParam:(NSDictionary*)param
          withExParam:(NSDictionary*)Exparam
           withMethod:(HTTPRequestMethod)method
              success:(void (^)(id result))success
   uploadFileProgress:(void(^)(NSProgress *uploadProgress))uploadFileProgress
              failure:(void (^)(NSError* erro))failure;

/**
 *  下载文件功能
 *
 *  @param URLString                 要下载文件的URL
 *  @param downloadFileProgress      下载的进度条，百分比
 *  @param setupFilePath             设置下载的路径
 *  @param downloadCompletionHandler 下载完成后（下载完成后可拿到存储的路径）
 */
+ (void)createDownloadFileWithURLString:(NSString *)URLString
                   downloadFileProgress:(void(^)(NSProgress *downloadProgress))downloadFileProgress
                          setupFilePath:(NSURL*(^)(NSURLResponse *response))setupFilePath
              downloadCompletionHandler:(void (^)(NSURL *filePath, NSError *error))downloadCompletionHandler;


#pragma mark 自定义协议 NSDictionary 默认菊花可见
//get
+ (NSURLSessionTask *)GET:(NSString *)url
               parameters:(id)parameters
                dictBlock:(OptionDict)optionDict
               errorBlock:(OptionError)optionError;
//get 联网菊花是否可见
+ (NSURLSessionTask *)GET:(NSString *)url
               parameters:(id)parameters
                dictBlock:(OptionDict)optionDict
               errorBlock:(OptionError)optionError
         indicatorVisible:(BOOL)visible;
//post
+ (NSURLSessionTask *)POST:(NSString *)url
                parameters:(id)parameters
                 dictBlock:(OptionDict)optionDict
                errorBlock:(OptionError)optionError;

//post 联网菊花是否可见
+ (NSURLSessionTask *)POST:(NSString *)url
                parameters:(id)parameters
                 dictBlock:(OptionDict)optionDict
                errorBlock:(OptionError)optionError
          indicatorVisible:(BOOL)visible;


#pragma mark - 自定义协议 NSData 默认菊花可见
//post 返回data
+ (NSURLSessionTask *)POST:(NSString *)url
                parameters:(id)parameters
                   success:(OptionData)optionData
                     error:(OptionError)optionError;
//post 菊花是否可见
+ (NSURLSessionTask *)POST:(NSString *)url
                parameters:(id)parameters
                   success:(OptionData)optionData
                     error:(OptionError)optionError
          indicatorVisible:(BOOL)visible;


#pragma mark 自定义协议头 header
//get
+ (NSURLSessionTask *)GET:(NSString *)url
                   header:(NSDictionary *)headerDic
               parameters:(id)parameters
                  timeOut:(NSTimeInterval)timeOut
                dictBlock:(OptionDict)optionDict
               errorBlock:(OptionError)optionError;
//post 包含传data
+ (NSURLSessionTask *)POST:(NSString *)url
                   headers:(NSDictionary *)headerDic
                   fileData:(NSData*)data
                  imageType:(NSString *)imageType
                parameters:(id)parameters
                   timeOut:(NSTimeInterval)timeOut
                 dictBlock:(OptionDict)optionDict
                errorBlock:(OptionError)optionError;
//post
+ (NSURLSessionTask *)POST:(NSString *)url
                    header:(NSDictionary *)headerDic
                parameters:(id)parameters
                   timeOut:(NSTimeInterval)timeOut
                 dictBlock:(OptionDict)optionDict
                errorBlock:(OptionError)optionError;
//put
+ (NSURLSessionTask *)PUT:(NSString *)url
                   header:(NSDictionary *)headerDic
               parameters:(id)parameters
                  timeOut:(NSTimeInterval)timeOut
                dictBlock:(OptionDict)optionDict
               errorBlock:(OptionError)optionError;
//delete
+ (NSURLSessionTask *)DELETE:(NSString *)url
                      header:(NSDictionary *)headerDic
                  parameters:(id)parameters
                     timeOut:(NSTimeInterval)timeOut
                   dictBlock:(OptionDict)optionDict
                  errorBlock:(OptionError)optionError;


#pragma mark - 获取ip地址
//是否是ipv4
+ (NSString *)getIPAddress:(BOOL)preferIPv4;
@end


